package com.gateway.pay.channel.strategy.response;

import com.gateway.pay.channel.dto.BaseRequest;
import com.gateway.pay.channel.dto.BaseResponse;
import com.gateway.pay.channel.dto.ErrorCode;
import com.gateway.pay.channel.dto.Result;

@Slf4j
public abstract class AbstractResponse implements IResponse {

    private static ErrorCode hasMatchingSubstring(String data) {
    /*    if (StringUtils.isBlank(data)) {
            return null;
        }
        for (String substring : THIRD_ERROR_MESSAGE) {
            if (data.contains(substring)) {
                return ErrorCode.getErrorCode(substring);
            }
        }*/
        return null;
    }

    public Result getResponse(BaseRequest request, String json) {

        ErrorCode errorCode = hasMatchingSubstring(json);
        BaseResponse response = BaseResponse.builder().build();
        if (errorCode != null) {
            response.setData(errorCode.getInfo());
            return Result.failure(response);
        }
        return doResponse(request, config, json);
    }

    protected abstract Result doResponse(BaseRequest request, LineConfig config, String json);

}
